from typing import List
from receiver.topic_handler import TopicHandler
from receiver.handler.drone_control_topic_handler import DroneControlTopicHandler
from receiver.handler.basic_aircraft_topic_handler import BasicAircraftTopicHandler


class TopicDispatcher:
    def __init__(self):
        self.topic_handler_list: List[TopicHandler] = []
        self.topic_handler_list.append(DroneControlTopicHandler())
        self.topic_handler_list.append(BasicAircraftTopicHandler())

    async def handler_message(self, message: dict, topic: str):
        for topic_handler in self.topic_handler_list:
            try:
                handler = await topic_handler.handle_message(message, topic)
                if handler == 0:
                    return
            except Exception as e:
                bid = topic_handler.get_bid(message)
                method = topic_handler.get_method(message)
                print("处理错误", e)